import { db } from "../cloudInit.js";
const _ = db.command;
import Query from "@/utils/Query.js";
const UnPublic = new Query({
    $cache: false,
    async $getPage(index) {
        const UnPublicData = db.collection("UnPublicXin").where({
            _openid: "{openid}",
        });
        const num = 10;
        if (index === 0) {
            const { total } = await UnPublicData.count();
            this.total = Math.ceil(total / num);
        }
        return UnPublicData.skip(index * num)
            .limit(num)
            .get()
            .then(({ data }) => {
                console.log(data);
                return data;
            });
    },
});
const Public = new Query({
    $cache: false,
    async $getPage(index) {
        const querying = db.collection("PublicXin").where({
            _openid: "{openid}",
        });
        const num = 10;
        if (index === 0) {
            const { total } = await querying.count();
            this.total = Math.ceil(total / num);
        }
        return querying
            .skip(index * num)
            .limit(num)
            .orderBy("date", "desc")
            .get()
            .then(({ data }) => {
                return data;
            });
    },
});
const Favorite = new Query({
    openId: "",
    async $getPage(index) {
        let {
            data: { likeArray },
        } = await db.collection("UserInfo").doc(this.openId).get();
        const num = 20;
        const Querying = db.collection("PublicXin").where({
            _id: _.in(likeArray),
        });
        if (index === 0) {
            const { total } = await Querying.count();
            this.total = Math.ceil(total / num);
        }
        return Querying.skip(index * num)
            .limit(num)
            .get()
            .then(({ data }) => {
                return data;
            });
    },
});
const Feedback = new Query({
    async $getPage(index) {
        const FeedbackData = db.collection("Feedback").where({
            _openid: "{openid}",
        });
        const num = 5;
        if (index === 0) {
            const { total } = await FeedbackData.count();
            this.total = Math.ceil(total / num);
        }
        return FeedbackData.skip(index * num)
            .limit(num)
            .get()
            .then(({ data }) => {
                console.log(data);
                return data;
            });
    },
});
export { Public, UnPublic, Feedback, Favorite };
